package com.item.springbootswagge.controller;

import com.google.common.util.concurrent.ListenableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncAnnotationAdvisor;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Component
public class Hello {

    Logger logger=LoggerFactory.getLogger(Hello.class);


    /**

     *@描述

     *@参数  [name]

     *@返回值  void

     *@创建人  wangdong

     *@创建时间  19-4-13/下午3:20

     *@修改人和其它信息

     */
    @Async
    public void sayHello(String name)throws Exception {
        Thread.sleep(5000);
        logger.info(name + ":执行成功！");
    }


    /**

     *@描述

     *@参数  [data]

     *@返回值  java.util.concurrent.Future<java.lang.String>

     *@创建人  wangdong

     *@创建时间  19-4-13/下午3:20

     *@修改人和其它信息

     */
    @Async
    public Future<String> asyncReturnFuture(String data) throws Exception{

        Thread.sleep(1000*1);
        logger.info(data + ":执行成功！");
        Future<String>future = new AsyncResult<String>("获取的结果:"+data);
        logger.info("执行结果："+future.toString());
        return future;
    }

}